"""
author:         ambitiouscat
email:          zw.ambitiouscat@gmail.com
time:           2021年4月6日 18:11:18
"""

from django.db import models
from base_object.BaseModel import BaseModel
from tinymce.models import HTMLField
from freeResource.global_setting import G_CharLength
from data.language.l_import import *
# Create your models here.

class GoodsType(BaseModel):
    """商品类型"""
    name = models.CharField(verbose_name='种类名',max_length=G_CharLength.L_ShopName);
    logo = models.CharField(verbose_name='标识名',max_length=G_CharLength.L_Name);
    image = models.ImageField(upload_to='type',verbose_name='商品类型图片');

    class Meta:
        db_table = 'fr_goods_type';
        verbose_name = l_good_type_verbose_name
        verbose_name_plural = l_good_type_verbose_name_pluarl

    def __str__(self):
        return self.name;


class GoodsInstance(BaseModel):
    """商品SKU"""
    goods_status = (
        (0,'上架'),
        (1, '下架'),
    )
    goods_type = models.ForeignKey(verbose_name='商品类型',to='GoodsType',on_delete=models.CASCADE);
    goods = models.ForeignKey(verbose_name='商品基本属性',to='Goods',on_delete=models.CASCADE);
    sub_name = models.CharField(verbose_name='商品子名称',max_length=G_CharLength.L_ShopName);
    name = models.CharField(verbose_name='商品名称',max_length=G_CharLength.L_Name);
    desc = models.CharField(verbose_name='商品简介',max_length=G_CharLength.L_ShopDesc);
    price = models.DecimalField(verbose_name='商品价格',max_digits=G_CharLength.L_MaxDigits,decimal_places=G_CharLength.L_DecimalPlaces);
    unite = models.CharField(verbose_name='商品单位',max_length=G_CharLength.L_ShopUnite);
    image = models.ImageField(upload_to='goods', verbose_name='商品图片')
    stock = models.IntegerField(default=0, verbose_name='商品库存')
    sales = models.IntegerField(default=0, verbose_name='商品销量')
    status = models.SmallIntegerField(default=1, choices=goods_status, verbose_name='商品状态')

    class Meta:
        db_table = 'fr_goods_sku'
        verbose_name = l_shop_sku_verbose_name
        verbose_name_plural = l_shop_sku_verbose_name_pluarl

    def __str__(self):
        return self.sub_name

class Goods(BaseModel):
    """商品SPU"""
    name = models.CharField(verbose_name='商品名称',max_length=G_CharLength.L_Name);
    detail = HTMLField(blank=True, verbose_name='商品详情')

    class Meta:
        db_table = 'fr_goods_spu'
        verbose_name = l_shop_spu_verbose_name
        verbose_name_plural = l_shop_spu_verbose_name_pluarl

    def __str__(self):
        return self.name

class GoodsImage(BaseModel):
    '''商品图片模型类'''
    goodIns = models.ForeignKey('GoodsInstance', on_delete=models.CASCADE, verbose_name='商品')  # 其实是存的sku的id
    image = models.ImageField(upload_to='goods', verbose_name='图片路径')

    class Meta:
        db_table = 'fr_goods_image'
        verbose_name = l_shop_img_verbose_name
        verbose_name_plural = l_shop_img_verbose_name_pluarl

# '首页轮播商品'
class IndexGoodsBanner(BaseModel):
    '''首页轮播商品展示模型类'''
    goodIns = models.ForeignKey('GoodsInstance', on_delete=models.CASCADE, verbose_name='商品')  # 其实是存的sku的id
    image = models.ImageField(upload_to='banner', verbose_name='图片')
    index = models.SmallIntegerField(default=0, verbose_name='展示顺序')  # 0 1 2 3

    class Meta:
        db_table = 'fr_index_banner'
        verbose_name = l_shop_banner_verbose_name
        verbose_name_plural = l_shop_banner_verbose_name_pluarl

    def __str__(self):
        return self.goodIns.name


# "主页分类展示商品"
class IndexTypeGoodsBanner(BaseModel):
    '''首页分类商品展示模型类'''
    DISPLAY_TYPE_CHOICES = (
        (0, "标题"),
        (1, "图片")
    )

    good_type = models.ForeignKey('GoodsType', on_delete=models.CASCADE, verbose_name='商品类型')  # 其实是存的GoodsType的id
    goodIns = models.ForeignKey('GoodsInstance', on_delete=models.CASCADE, verbose_name='商品SKU')  # 其实是存的GoodsSKU的id
    display_type = models.SmallIntegerField(default=1, choices=DISPLAY_TYPE_CHOICES, verbose_name='展示类型')
    index = models.SmallIntegerField(default=0, verbose_name='展示顺序')

    class Meta:
        db_table = 'fr_index_type_goods'
        verbose_name = l_shop_home_type_verbose_name
        verbose_name_plural = l_shop_home_type_verbose_name_pluarl

    def __str__(self):
        return '%s - %s' % (self.good_type.name, self.goodIns.name)


# "主页促销活动"
class IndexPromotionBanner(BaseModel):
    '''首页促销活动模型类'''
    name = models.CharField(max_length=G_CharLength.L_Name, verbose_name='活动名称')
    url = models.CharField(max_length=G_CharLength.L_URL, verbose_name='活动链接')
    image = models.ImageField(upload_to='banner', verbose_name='活动图片')  # 去调用FastDfs存储图片
    index = models.SmallIntegerField(default=0, verbose_name='展示顺序')

    class Meta:
        db_table = 'fr_index_promotion'
        verbose_name = l_shop_home_promote_verbose_name
        verbose_name_plural = l_shop_home_promote_verbose_name_pluarl

    def __str__(self):
        return self.name
